<?php


namespace Tbf\Bundle\AlipayBundle\Api;


use Guzzle\Http\Url;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Tbf\Bundle\AlipayBundle\Entity\Transaction;
use Tbf\Bundle\AlipayBundle\Model\AlipaySign;
use Tbf\Bundle\AlipayBundle\Model\CreatePaymentRequest;
use Tbf\Component\Arrays\ArrayFunction;

/**
 * 即时到帐
 * 1.如果用户传入tradeid,并且这个tradeid已经存在 -> 用户对某个事务尝试多次发起请求 -> 使用原先的事务
 * 2.如果用户不传入tradeid,生成一个uuid模样的tradeid,这个支付请求不能重复发了...
 * 3.并发保证成功api回调最多发生一次(不管成功page回调)
 * 4.已完成的某个tradeid不允许发起支付(在这里报错)
 */
class CreateDirectPayByUser extends AbstractCreatePayment{
    protected function buildRequestData(CreatePaymentRequest $request){
        return array(
            '_input_charset'=>'utf-8',
            'notify_url'=>$this->config->getCdbuNotifyUrl(),
            'out_trade_no'=>$request->getTradeId(),
            'partner'=>$this->config->getAppKey(),
            'payment_type'=>1,
            'return_url'=>$this->config->getCdbuReturnUrl(),
            'service'=>'create_direct_pay_by_user',
            'subject'=>$request->getSubject(),
            'total_fee'=>$request->getMoney(),
            'sign_type'=>'MD5',
        );
    }
    protected function getCreatePaymentType(){
        return Transaction::TYPE_CREATE_DIRECT_PAY_BY_USER;
    }
}